# -*- coding: utf-8 -*-

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service as ChromeDriverService
from selenium.webdriver.chrome.options import Options

def test_first_selenium_for_chrome():
    
    # 启动会话
    chrome_driver_path = "/home/shengyi/program/chrometest/chromedriver/chromedriver" # 指定ChromeDriver的路径
    options = Options()
    options.binary_location = "/home/shengyi/program/chrometest/chrome/chrome" # 指定Chrmoea浏览器的路径
    service = ChromeDriverService(executable_path=chrome_driver_path)
    driver = webdriver.Chrome(service=service, options=options)

    # 在浏览器上执行动作，此处是指定浏览器要打开的网址（selenium官网提供的测试地址）
    url = "https://www.selenium.dev/selenium/web/web-form.html"
    driver.get(url)

    # 请求浏览器的信息：获取指定网址执行结果
    title = driver.title

    # 设置等待策略：此处是固定等待0.5S
    driver.implicitly_wait(0.5)

    # 定位指定的界面元素
    text_box = driver.find_element(by=By.NAME, value="my-text")
    submit_button = driver.find_element(by=By.CSS_SELECTOR, value="button")

    # 在定位到的元素上执行动作
    text_box.send_keys("Selenium")
    submit_button.click()

    # 获取元素执行动作后的信息
    message = driver.find_element(by=By.ID, value="message")
    value = message.text
    assert value == "Received!"